package com.iwhalecloud.bss.kite.cucc.service.custview;

import java.util.Optional;

import com.google.common.collect.Lists;
import com.iwhalecloud.bss.kite.common.constant.SymbolConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.dto.pos.KitePosDTO;
import com.iwhalecloud.bss.kite.cucc.client.vo.custview.CustViewAttr;
import com.iwhalecloud.bss.kite.cucc.client.vo.custview.CustViewBaseVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.custview.CustViewVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.custview.GroupCustInfoVO;
import com.iwhalecloud.bss.kite.cucc.service.attr.LocalAttrHelper;
import com.iwhalecloud.bss.kite.cucc.service.custview.evolve.task.GroupCustInfoTask;

/**
 * @ClassName : GetGroupCustInfoTask
 * @Description : 集团客户信息
 * @Author : xie.zhengjun
 * @Date : 2021/1/22 0:11
 * @deprecated 已停止维护，请勿使用。改进版本解除Callable绑定，干干净净，只专注业务本身。见：{@link GroupCustInfoTask}
 */
public class GetGroupCustInfoTask extends CustViewBaseTask {
    public GetGroupCustInfoTask(Object[] args) {
        super(args);
    }

    @Override
    public CustViewBaseVO call() throws Exception {
        Object[] args = getArgs();
        if (args.length != 3) {
            return null;
        }
        KitePosDTO kitePosDTO = (KitePosDTO) args[0];
        CustViewVO custViewVO = (CustViewVO) args[1];
        String queryType = (String) args[2];

        GroupCustInfoVO custInfoVO = new GroupCustInfoVO();
        custViewVO.setGroupCust(custInfoVO);
        Optional.ofNullable(kitePosDTO.getCustomer()).ifPresent(kitePosCustomerDTO -> {
            String custRegion = String
                .join(SymbolConsts.HYPHEN, LocalAttrHelper.getRegionName(kitePosCustomerDTO.getEparchyProvince()),
                    LocalAttrHelper.getRegionName(kitePosCustomerDTO.getEparchyCity()),
                    LocalAttrHelper.getRegionName(kitePosCustomerDTO.getEparchyArea()));
            String custRegionCode = String
                .join(SymbolConsts.HYPHEN, kitePosCustomerDTO.getEparchyProvince(), kitePosCustomerDTO.getEparchyCity(),
                    kitePosCustomerDTO.getEparchyArea());
            if (KiteStringUtils.isEqual("1", queryType)) {
                custInfoVO.setAttrs(Lists.newArrayList(
                    new CustViewAttr("成员客户名称", kitePosCustomerDTO.getName(), kitePosCustomerDTO.getName()),
                    new CustViewAttr("成员客户编码", kitePosCustomerDTO.getGroupId(), kitePosCustomerDTO.getGroupId()),
                    new CustViewAttr("成员客户归属地", custRegionCode, custRegion)));
            }
            else {
                custInfoVO.setAttrs(Lists.newArrayList(
                    new CustViewAttr("集团客户名称", kitePosCustomerDTO.getName(), kitePosCustomerDTO.getName()),
                    new CustViewAttr("集团客户编码", kitePosCustomerDTO.getGroupId(), kitePosCustomerDTO.getGroupId()),
                    new CustViewAttr("客户归属地", custRegionCode, custRegion)));
            }
        });
        return custInfoVO;
    }
}
